package com.appleyk.service.impl;

import java.util.List;

import com.appleyk.mapping.DepartmentMapping;
import com.appleyk.mapping.EmployeesMapping;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import com.appleyk.core.CoreProcessor;
import com.appleyk.service.QuestionService;

import javax.annotation.Resource;

@Service
@Primary
public class QuestionServiceImpl implements QuestionService {

    @Resource
    private EmployeesMapping employeesMapping;

    @Resource
    private DepartmentMapping departmentMapping;

    @Autowired
    private CoreProcessor queryProcess;

    @Override
    public String answer(String question) throws Exception {
        List<String> reStrings = queryProcess.analysis(question);
        int modelIndex = Integer.parseInt(reStrings.get(0));
        String answer =null;
        String name;
        if(CollectionUtils.isEmpty(reStrings)){
            return "抱歉,我没有找到你要的答案";
        }
        switch (modelIndex) {
            case 0:
                name = reStrings.get(1);
                answer = employeesMapping.getEmployeesPositionsName(name);
                break;
            case 1: // 查询 员工 性别
                answer = employeesMapping.getEmployeesSex(reStrings);
                break;
            case 2: // 查询 员工 出生日期
                answer = employeesMapping.getEmployeesBirthDate(reStrings);
                break;
            case 3: // 查询 员工 身份证
                answer = employeesMapping.getEmployeesIdNumber(reStrings);
                break;
            case 4: // 查询 员工 联系方式
                answer = employeesMapping.getEmployeesContactInfo(reStrings);
                break;
            case 5: // 查询 员工 家庭住址
                answer = employeesMapping.getEmployeesAddress(reStrings);
                break;
            case 6: // 查询 员工 岗位详情
                answer = employeesMapping.getEmployeesPositionDetail(reStrings);
                break;
            case 7: // 查询 员工 部门
                answer = employeesMapping.getEmployeesDepartments(reStrings);
                break;
            case 8: // 查询 员工 部门详情
                answer = employeesMapping.getEmployeesDepartmentsDetail(reStrings);
                break;
            case 9: // 查询 员工 员工数量
                answer = employeesMapping.getEmployeesCount();
                break;
            case 10: // 查询 员工 男员工数量
                answer = employeesMapping.getEmployeesMaleCount();
                break;
            case 11: // 查询 员工 女员工数量
                answer = employeesMapping.getEmployeesFemaleCount();
                break;
            case 12: // 查询 大于 x 岁员工多少
                answer = employeesMapping.getEmployeesThanX(reStrings);
                break;
            case 13: // 查询 小于 x 岁员工多少
                answer = employeesMapping.getEmployeesLowX(reStrings);
                break;
            case 14: // 查询 部门 详情
                answer = departmentMapping.getDepartments(reStrings);
                break;
            case 15: // 查询 部门 人数
                answer = departmentMapping.getDepartmentsEmpNumber(reStrings);
                break;
            case 16: // 查询 部门 有哪些人
                answer = departmentMapping.getDepHaveEmp(reStrings);
                break;
            case 17: // 查询 部门 有哪些岗位
                answer = departmentMapping.getDepHavePosName(reStrings);
                break;
            case 18: // 查询 员工 信息
                answer = employeesMapping.getEmployeesInfo(reStrings);
                break;
            case 19: // 查询 员工 加入公司时间
                answer = employeesMapping.getEmployeesJoinTime(reStrings);
                break;
            case 20: // 查询 员工 邮箱
                answer = employeesMapping.getEmployeesEmail(reStrings);
                break;
            case 21: // 查询 员工 政治面貌
                answer = employeesMapping.getEmployeesHighestDegree(reStrings);
                break;
            case 22: // 查询 员工 最高学历
                answer = employeesMapping.getEmployeesPoliticalProfile(reStrings);
                break;
            case 23: // 查询 员工 籍贯
                answer = employeesMapping.getEmployeesHometown(reStrings);
                break;
            case 24: // 查询 员工 紧急联系人
                answer = employeesMapping.getEmployeesEmergencyContact(reStrings);
                break;
            case 25: // 查询 员工 紧急联系人电话
                answer = employeesMapping.getEmployeesEmergencyContactPhone(reStrings);
                break;
            case 26: // 查询 员工 毕业学校
                answer = employeesMapping.getEmployeesGraduateSchool(reStrings);
                break;
            case 27: // 查询 员工 民族
                answer = employeesMapping.getEmployeesNation(reStrings);
                break;
            case 28: // 查询 员工 户籍所在地
                answer = employeesMapping.getEmployeesHousehold(reStrings);
                break;
            case 29: // 查询 员工 证书
                answer = employeesMapping.getEmployeesCertificate(reStrings);
                break;
            case 30: // 查询 员工 工作经历
                answer = employeesMapping.getEmployeesWorkHistory(reStrings);
                break;
            default:
                break;
        }
        System.out.println(answer);
        if (answer != null && !"".equals(answer) && !("\\N").equals(answer)) {
            return answer;
        } else {
            return "抱歉,我没有找到你要的答案";
        }
    }

}
